extends Node

var http_request: HTTPRequest
var url: String = "https://api.github.com/repos/shikeik/project-template/contents/multiplayergamedemo/official-server.json?ref=main"
var token: String = "YOUR_GITHUB_TOKEN"  # 替换为你的 GitHub Token

func _ready():
	# 创建 HTTPRequest 实例
	http_request = HTTPRequest.new()
	add_child(http_request)

	# 连接请求完成信号
	http_request.request_completed.connect(_on_request_completed)

	# 设置请求头，包含 Authorization Token
	var headers = ["Authorization: token " + token]
	
	# 发起 GET 请求
	var error = http_request.request(url, headers)
	
	if error != OK:
		print("请求失败:", error)
	else:
		print("请求已发送")
		
# 处理请求完成信号
func _on_request_completed(result, response_code, headers, body):
	if response_code == 200:
		# 请求成功，解析 JSON 数据
		var json = JSON.new()
		var parse_result = json.parse(body.get_string_from_utf8())
		if parse_result == OK:
			var json_data = json.get_data()
			print("文件内容:", json_data)
		else:
			print("JSON 解析失败")
	else:
		print("请求失败，响应代码:", response_code)
